﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IE = Interop.SHDocVw;
using AddinExpress.IE;
 

namespace StockSBIE
{
    public partial class SBConfigForm : Form
    {
        public SBConfigForm()
        {
            InitializeComponent();
        }

        protected IEModule m_module;
        public void setIEModule(IEModule module)
        {
            m_module = module;
        }
             
            
        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("attach");
            DateTime d= DateUtils.getValidTradeDate(DateTime.Now);
            String url = String.Format("http://www.twse.com.tw/ch/trading/exchange/MI_INDEX/genpage/Report{0}/A112{1}ALLBUT0999_1.php?select2=ALLBUT0999&chk_date={2}", DateUtils.getYYYYMMPlanString(d), DateUtils.getPlanString(d), DateUtils.getROCString(d));
            m_module.IEApp.Navigate(url);
            ////101/06/29
        }
        StockDataManager manager = new StockDataManager();                
        private void button2_Click(object sender, EventArgs e)
        {

            manager.preLoadCode();
            DateTime dataDate = DateTime.Now;
            List<List<String>> rows = m_module.processDailyTradeData(out dataDate);
            if (rows == null)
                return;
            manager.preloadStockDaily(dataDate);
            
            int rsz = rows.Count;
            progressBar1.Maximum = rsz;
            int ri = 0;
            foreach (List<String> row in rows)
            {
                if (row[0].Contains("證券"))
                    continue;
                manager.updateStockDaily(dataDate, row, "tse");
                ri++;
                progressBar1.Value = ri;
                if (ri % 50==0)
                    Application.DoEvents();
            }
        }

        private void SBConfigForm_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {


        }
    }
}
